﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using InstantNaukriDAL;
using System.IO;

public partial class ResumeDetails : System.Web.UI.Page
{
    string cvpath = "";
    string downloadtill = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserId"] != null)
        {

            clsUserLoginDAL objclsUserLoginDAL = new clsUserLoginDAL();
            string uid = Convert.ToString(Request.QueryString["userid"]);
            if (uid != "")
            {
                IN_TB_USER objIN_TB_USER = new IN_TB_USER();
                objIN_TB_USER = objclsUserLoginDAL.GetUserByID(Convert.ToInt32(uid));
                if (objIN_TB_USER != null)
                    lblName.Text = Convert.ToString(objIN_TB_USER.NAME);
                clsProfileDAL objclsProfileDAL = new clsProfileDAL();
                IN_TB_PROFILE objIN_TB_PROFILE = new IN_TB_PROFILE();
                objIN_TB_PROFILE = objclsProfileDAL.GetProfileByUserId(Convert.ToInt32(uid));
                if (objIN_TB_PROFILE != null)
                {
                    if (Convert.ToString(objIN_TB_PROFILE.GENDER) == "0")
                        lblGender.Text = "Male";
                    if (Convert.ToString(objIN_TB_PROFILE.GENDER) == "1")
                        lblGender.Text = "Female";
                    int Preferred_locationId = Convert.ToInt32(objIN_TB_PROFILE.CITY);
                    clsCity objclsCity = new clsCity();
                    IN_TB_CITY objIN_TB_CITY = new IN_TB_CITY();
                    objIN_TB_CITY = objclsCity.GetCityById(Preferred_locationId);
                    if (objIN_TB_CITY != null)
                        lblCity.Text = Convert.ToString(objIN_TB_CITY.CITY);
                    clsResumeDAL objclsResumeDAL = new clsResumeDAL();
                    IN_TB_RESUME_MST objIN_TB_RESUME_MST = new IN_TB_RESUME_MST();
                    objIN_TB_RESUME_MST = objclsResumeDAL.GetResumeByUserId(Convert.ToInt32(uid));
                    if (objIN_TB_RESUME_MST != null)
                        lblResumeHeadline.Text = Convert.ToString(objIN_TB_RESUME_MST.RESUME_HEADLINE);
                    if (objIN_TB_USER != null)
                    {
                        if (objIN_TB_USER.CREATED_BY != null)
                        {
                            if (Convert.ToInt32(objIN_TB_USER.CREATED_BY) == 1)
                            {
                                lblRegisteredBy.Text = "Admin";
                                lblFranchisee.Text = "Admin";
                            }
                        }
                        if (objIN_TB_USER.CREATED_ON != null)
                        {
                            DateTime rd = Convert.ToDateTime(objIN_TB_USER.CREATED_ON);
                            lblRegistrationDate.Text = rd.ToString("dd-MMM-yyyy");
                        }
                    }
                }
            }
            string skillset = Convert.ToString(Request.QueryString["skillset"]);
            if (skillset != "" && skillset != null)
            {
                skillset = clsEncryptionDecryption.DecryptQueryString(skillset);
                lblKeySkills.Text = skillset;
            }
            string email = Convert.ToString(Request.QueryString["email"]);
            if (email != "" && email != null)
            {
                email = clsEncryptionDecryption.DecryptQueryString(email);
                lblEmail.Text = email;
            }
            string mobile = Convert.ToString(Request.QueryString["mobile"]);
            if (mobile != "" && mobile != null)
            {
                mobile = clsEncryptionDecryption.DecryptQueryString(mobile);
                lblMobile.Text = mobile;
            }
            string phone = Convert.ToString(Request.QueryString["phone"]);
            if (phone != "" && phone != null)
            {
                phone = clsEncryptionDecryption.DecryptQueryString(phone);
                lblPhone.Text = phone;
            }
            string experience = Convert.ToString(Request.QueryString["experience"]);
            if (experience != "" && experience != null)
            {
                experience = clsEncryptionDecryption.DecryptQueryString(experience);
                lblTotalExperience.Text = experience;
            }
            string currentcomp = Convert.ToString(Request.QueryString["currentcomp"]);
            if (currentcomp != "" && currentcomp != null)
            {
                currentcomp = clsEncryptionDecryption.DecryptQueryString(currentcomp);
                lblCurrentCompany.Text = currentcomp;
            }
            string currentdesig = Convert.ToString(Request.QueryString["currentdesig"]);
            if (currentdesig != "" && currentdesig != null)
            {
                currentdesig = clsEncryptionDecryption.DecryptQueryString(currentdesig);
                lblCurrentDesignation.Text = currentdesig;
            }
            cvpath = Convert.ToString(Request.QueryString["cvpath"]);
            if (cvpath != "" && cvpath != null)
            {
                cvpath = clsEncryptionDecryption.DecryptQueryString(cvpath);
                lblBasicQualification.Text = cvpath;
            }
            downloadtill = Convert.ToString(Request.QueryString["downloadtill"]);
            if (downloadtill != "" && downloadtill != null)
            {
                downloadtill = clsEncryptionDecryption.DecryptQueryString(downloadtill);
                DateTime dt = Convert.ToDateTime(downloadtill);
                if (DateTime.Today >= dt.Date)
                {
                    lblDownload.Text = "Download limit Exceeded.";
                    lnkDownloadCV.Enabled = false;
                }
                else
                {
                    lblDownload.Text = "Download CV";
                    lnkDownloadCV.Enabled = true;
                }
            }
            string currentloc = Convert.ToString(Request.QueryString["currentloc"]);

            if (currentloc != "" && currentloc != null)
            {
                currentloc = clsEncryptionDecryption.DecryptQueryString(currentloc);
                int Preferred_locationId = Convert.ToInt32(currentloc);
                clsCity objclsCity = new clsCity();
                IN_TB_CITY objIN_TB_CITY = new IN_TB_CITY();
                objIN_TB_CITY = objclsCity.GetCityById(Preferred_locationId);
                lblCurrentLocation.Text = objIN_TB_CITY.CITY;
            }
            string currentctc = Convert.ToString(Request.QueryString["currentctc"]);
            if (currentctc != "" && currentctc != null)
            {
                currentctc = clsEncryptionDecryption.DecryptQueryString(currentctc);
                lblCurrentCTC.Text = currentloc;
            }
            string functionalarea = Convert.ToString(Request.QueryString["functionalarea"]);

            if (functionalarea != "" && functionalarea != null)
            {
                functionalarea = clsEncryptionDecryption.DecryptQueryString(functionalarea);
                int Functional_AreaId = Convert.ToInt32(functionalarea);
                clsFunctionalAreaDAL objclsFunctionalAreaDAL = new clsFunctionalAreaDAL();
                IN_TB_FUNCTIONAL_AREA objIN_TB_FUNCTIONAL_AREA = new IN_TB_FUNCTIONAL_AREA();
                objIN_TB_FUNCTIONAL_AREA = objclsFunctionalAreaDAL.GetAllFunctionalAreaById(Functional_AreaId);
                lblFunctionalArea.Text = objIN_TB_FUNCTIONAL_AREA.FUNCTIONAL_AREA;

            }
            string preferredlocation = Convert.ToString(Request.QueryString["preferredlocation"]);
            if (preferredlocation != "" && preferredlocation != null)
            {
                preferredlocation = clsEncryptionDecryption.DecryptQueryString(preferredlocation);
                int Preferred_locationId = Convert.ToInt32(preferredlocation);
                clsCity objclsCity = new clsCity();
                IN_TB_CITY objIN_TB_CITY = new IN_TB_CITY();
                objIN_TB_CITY = objclsCity.GetCityById(Preferred_locationId);
                lblPreferredLocation.Text = objIN_TB_CITY.CITY;

            }
        }
    }
    protected void lnkDownloadCV_Click(object sender, ImageClickEventArgs e)
    {
        try
        {
            var filePath = Server.MapPath("~/Resumes/" + Convert.ToString(cvpath));
            if (!File.Exists(filePath))
                return;
            if (cvpath != "")
            {
                var fileInfo = new System.IO.FileInfo(filePath);
                Response.ContentType = "application/octet-stream";
                Response.AddHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\"", filePath));
                Response.AddHeader("Content-Length", fileInfo.Length.ToString());
                Response.WriteFile(filePath);
                Response.End();
            }
        }
        catch (Exception)
        {
            throw;
        }
    }
}
